public class Solution443 {

    public int compress(char[] chars) {
        int i=0;
        int ans=0;
        int start=0;
        while (i<chars.length){
            int count=1;
            while (i+1<chars.length&&chars[i]==chars[i+1]){
                i++;count++;
            }
            chars[start]=chars[i];start++;
            if (count!=1){
                String c=String.valueOf(count);
                int len=c.length();
                for (int j=0;j<len;j++){
                    chars[start]=c.charAt(j);
                    start++;
                }
                ans=ans+1+len;
            }else
                ans=ans+1;
            i++;
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution443().compress(new char[]{'a','b','b','b','b','b','b','b','b','b','b','b','b'}));
    }
}
